﻿<!--
> Muaz Khan     - https://github.com/muaz-khan 
> MIT License   - https://www.webrtc-experiment.com/licence/
> Experiments   - https://github.com/muaz-khan/WebRTC-Experiment
-->

<!DOCTYPE html>
<html id="home" lang="en">

    <head>
        <title>WebRTC RTP Usage | Muaz Khan</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
        <link rel="author" type="text/html" href="https://plus.google.com/+MuazKhan">
        <meta name="author" content="Muaz Khan">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" href="https://cdn.webrtc-experiment.com/style.css">
        <style>
            p { padding: .8em; }

            li {
                border-bottom: 1px solid rgb(189, 189, 189);
                border-left: 1px solid rgb(189, 189, 189);
                padding: .5em;
            }
        </style>
        <!-- for HTML5 el styling -->
        <script>
            document.createElement('article');
            document.createElement('footer');
        </script>
    </head>

    <body>
        <article>
            <header style="text-align: center;">
                <h1><a href="https://www.webrtc-experiment.com/">WebRTC</a> RTP Usage</h1>
                <p>
                    <a href="https://www.webrtc-experiment.com/">HOME</a>
                    <span> &copy; </span>
                    <a href="http://www.MuazKhan.com/" target="_blank">Muaz Khan</a>
                    .
                    <a href="http://twitter.com/WebRTCWeb" target="_blank" title="Twitter profile for WebRTC Experiments">@WebRTCWeb</a>
                    
                    .
                    <a href="https://github.com/muaz-khan?tab=repositories" target="_blank" title="Github Profile">Github</a>
                    
                    .
                    <a href="https://github.com/muaz-khan/WebRTC-Experiment/issues?state=open" target="_blank">Latest issues</a>
                    
                    .
                    <a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">What's New?</a>
                </p>
            </header>

            <div class="github-stargazers"></div>

            <blockquote style="background: #f3b7b7;border: 5px solid black;border-radius: 5px;">
                This tutorial is <span style="border: 1px dotted red; background: yellow; padding: 2px 5px;">out-dated (written in 2013)</span>. WebRTC implementation is heavily changed since then. So please do NOT refer or rely on this page.
            </blockquote>
            
            <p>
                Note: Chrome usually bundles & multiplexes media ports over single UDP port. Below all scenarios are for <strong>non-bundled</strong> media connections.
            </p>
		
            <h2>Simple Scenario: One-to-One audio/video sharing</h2>
		
            <p>
                In this scenario; maximum <strong>4 RTP ports</strong> are opened for each peer:
            </p>
		
            <ol>
                <li>One RTP port for <strong>outgoing video</strong></li>
                <li>One RTP port for <strong>outgoing audio</strong></li>
                <li>One RTP port for <strong>incoming video</strong></li>
                <li>One RTP port for <strong>incoming audio</strong></li>
            </ol>
		
            <p>
                Each RTP port is using <strong>1 MB</strong> bandwidth. It means that <strong>4 MB</strong> bandwidth is acquired by each peer.
            </p>
		
            <p>
                Remember, you can use '<strong>b=AS</strong>' to increase/decrease bandwidth usage for each stream; which will be divided according to number of RTP ports for each stream.
            </p>
		
            <h2>One-Way audio/video sharing Scenario</h2>
		
            <p>
                There are two kinds of users in this scenario:
            </p>
		
            <ol>
                <li>Broadcaster or Session-initiator</li>
                <li>Participant or Roommate</li>
            </ol>
		
            <h2>Broadcaster in One-Way Scenario</h2>
		
            <p>
                <strong>2 RTP ports</strong> are opened for broadcasting peer:
            </p>
		
            <ol>
                <li>One RTP port for <strong>outgoing video</strong></li>
                <li>One RTP port for <strong>outgoing audio</strong></li>
            </ol>
		
            <p>
                There is no <strong>incoming</strong> RTP ports.
            </p>
		
            <p>
                <strong>2 MB</strong> audio/video bandwidth is required and used by the broadcasting peer. Because there are two outgoing RTP ports.
            </p>
		
            <h2>Participant in One-Way Scenario</h2>
		
            <p>
                <strong>2 RTP ports</strong> are opened for participating peer:
            </p>
		
            <ol>
                <li>One RTP port for <strong>incoming video</strong></li>
                <li>One RTP port for <strong>incoming audio</strong></li>
            </ol>
		
            <p>
                There is no <strong>outgoing</strong> RTP ports.
            </p>
		
            <p>
                <strong>2 MB</strong> audio/video bandwidth is required and used by the participating peer. Because there are two incoming RTP ports.
            </p>
		
		
            <h2>Video-Conferencing i.e. Many-to-Many Scenario</h2>
		
            <p>
                In this scenario; number of RTP ports depends upon number of peer connections multiplied by 4.
            </p>
		
            <h2>10-users video-conferencing</h2>
		
            <p>
                <strong>40 RTP ports</strong> are opened for each user; i.e. <strong>40 MB</strong> bandwidth is used by each user.
            </p>
		
            <ol>
                <li>10 RTP port for <strong>outgoing</strong> video / <strong>10 MB</strong> bandwidth usage</li>
                <li>10 RTP port for <strong>outgoing</strong> audio / <strong>10 MB</strong> bandwidth usage</li>
                <li>10 RTP port for <strong>incoming</strong> video / <strong>10 MB</strong> bandwidth usage</li>
                <li>10 RTP port for <strong>incoming</strong> audio / <strong>10 MB</strong> bandwidth usage</li>
            </ol>
		
            <h2>How to use <strong>b=AS</strong>?</h2>
            <pre>
// remove existing bandwidth lines
sdp = sdp.replace( /b=AS([^\r\n]+\r\n)/g , '');

// audio bandwidth 50 kilobits per second
sdp = sdp.replace( /a=mid:<strong>audio</strong>\r\n/g , 'a=mid:audio\r\n<strong>b=AS:50</strong>\r\n');

// video bandwidth 256 kilobits per second
sdp = sdp.replace( /a=mid:<strong>video</strong>\r\n/g , 'a=mid:video\r\n<strong>b=AS:256</strong>\r\n');

// data bandwidth 1638400 kilobits per second
sdp = sdp.replace( /a=mid:<strong>data</strong>\r\n/g , 'a=mid:data\r\n<strong>b=AS:1638400</strong>\r\n');
</pre>
            <p>
                Above snippet is setting bandwidth for first track in each m-line. You need to set application specific bandwidth attribute for each track if you attached multiple streams.
            </p>
		
            <h2>One-to-One and Multiple Streams Scenario</h2>
		
            <p>
                Assume that you attached following streams per single peer:
            </p>
		
            <ol>
                <li>Audio+Video Stream</li>
                <li>Screen Sharing Stream</li>
                <li>Only Video stream coming from a second webcam</li>
            </ol>
		
            <p>
                In this scenario; <strong>8 RTP ports</strong> will be opened for each peer:
            </p>
		
            <ol>
                <li><strong>4 RTP port</strong> for outgoing/incoming <strong>audio+video</strong> streams</li>
                <li><strong>2 RTP port</strong> for outgoing/incoming <strong>screen sharing</strong> streams</li>
                <li><strong>2 RTP port</strong> for outgoing/incoming <strong>video-only</strong> streams</li>
            </ol>
		
            <p>
                In such scenario; default bandwidth acquired by each peer is <strong>8 MB</strong>.
            </p>
		
            <h2>For Your Information...</h2>		

            <p>
                By default, 5 simultaneous calls need 20M bandwidth, as 2M each. You can also try to limit each stream by adding 'b=AS' according to your available bandwidth.
            </p>
		
            <table>
                <tr>
                    <td>Maximum video bitrate</td>
                    <td>2</td>
                    <td>Mbps</td>
                </tr>
			
                <tr>
                    <td>Minimum video bitrate</td>
                    <td>.05</td>
                    <td>Mbps</td>
                </tr>
			
                <tr>
                    <td>Starting video bitrate</td>
                    <td>.3</td>
                    <td>Mbps</td>
                </tr>
            </table>
		
            <p>
                <a href="https://code.google.com/p/chromium/codesearch#chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine.cc&q=webrtcvideoen&sq=package:chromium&l=92" target="_blank">Reference</a>.
            </p>

            <br />
            <br />
            <section style="border: 1px solid rgb(189, 189, 189); border-radius: .2em; margin: 1em 3em;">
                <h2 id="feedback" style="border-bottom: 1px solid rgb(189, 189, 189); padding: .2em .4em;">Feedback</h2>
                <div>
                    <textarea id="message" style="border: 1px solid rgb(189, 189, 189); height: 8em; margin: .2em; outline: none; resize: vertical; width: 98%;" placeholder="Have any message? Suggestions or something went wrong?"></textarea>
                </div>
                <button id="send-message" style="font-size: 1em;">Send Message</button><small style="margin-left: 1em;">Enter your email too; if you want "direct" reply!</small>
            </section>
        </article>
        
        <a href="https://github.com/muaz-khan/WebRTC-Experiment" class="fork-left"></a>
        
        <footer>
            <p>
                <a href="https://www.webrtc-experiment.com/">WebRTC Experiments</a>
                © <a href="https://plus.google.com/+MuazKhan" rel="author" target="_blank">Muaz Khan</a>
                <a href="mailto:muazkh@gmail.com" target="_blank">muazkh@gmail.com</a>
            </p>
        </footer>
    
        <!-- commits.js is useless for you! -->
        <script src="https://cdn.webrtc-experiment.com/commits.js" async> </script>
    </body>
</html>
